//
//  adnewViewController.m
//  iosnew
//
//  Created by sunzhongxiang on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "adnewViewController.h"
#import "myTableViewCell.h"
#import "wangyeViewController.h"
#define gao 59
#define id   zhang

@interface adnewViewController ()

@end

@implementation adnewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataSource = @[
                    @{
                        @"headerTitle": @"我是header",
                        @"footerTitle": @"我是footer",
                        @"list":@[
                               @{
                                    @"title": @"我是cellone的title",
                                    },
                                @{
                                    @"title":@"我是collone的title",
                                    }
                                ]
                        },
                    @{
                        @"headerTitle": @"我是第二个header",
                        @"footerTitle": @"我是第二个footerr",
                        @"list": @[
                                @{
                                    @"title": @"我是第二个cellTwo的title",
                                    },
                                @{
                                    @"title": @"我是第二个cellTwo的title",
                                    }
                                ]
                        }

                    ];
    [[NSUserDefaults standardUserDefaults]setValue:@"it is me" forKey:@"name"];
    [[NSUserDefaults standardUserDefaults]setValue:[NSNumber numberWithInt:1] forKey:@"age"];
    [[NSUserDefaults standardUserDefaults]setValue:@{@"title":@"我是titile"}forKey:@"age"];
    [[NSUserDefaults standardUserDefaults]setValue:@[@"1",@"fiker"] forKey:@"any123"];
    NSArray *all = [[NSUserDefaults standardUserDefaults]objectForKey:@"any123"];
    // Do any additional setup after loading the view from its nib.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    wangyeViewController *nv = [[wangyeViewController alloc] init];
    [self.navigationController pushViewController:nv animated:YES];
    UIAlertView *akert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要进入吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [akert show];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return gao;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, 320, 59);
    view.backgroundColor = [UIColor yellowColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 21)];
    NSDictionary *a1 =[_dataSource objectAtIndex:section];
    label.text = a1[@"headerTitle"];
    [view addSubview:label];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 59)];
    view.backgroundColor = [UIColor yellowColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 21)];
    NSDictionary *bigDic = [_dataSource objectAtIndex:section];
    label.text = bigDic[@"footerTitle"];
    
    [view addSubview:label];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return gao;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSDictionary *bigDic = [_dataSource objectAtIndex:section];
    NSArray *listArr = bigDic[@"list"];
    return listArr.count;
    
}
- (myTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *indentifier = @"myTableViewCell";
    myTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (cell == nil) {
        //        cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:indentifier];
        
        cell = [[[NSBundle mainBundle] loadNibNamed:@"myTableViewCell" owner:self options:nil] lastObject];
    }
    NSDictionary *bigDic = [_dataSource objectAtIndex:indexPath.section];
    NSArray *listArr = bigDic[@"list"];
    NSDictionary *smallDic = [listArr objectAtIndex:indexPath.row];
    cell.titleLabel.text = smallDic[@"title"];
    cell.contentLabel.text =smallDic[@"content"];
    
    
    return cell;
    
}

-(void) sanmu
{
    int a,b;
    a=1;
    b=2;
    a>b?NSLog(@"大"):NSLog(@"xiao");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataSource.count;}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
        return 59;
}


// 第二个页面将要出现

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    NSLog(@"页面viewWillAppear");
    
}

// 第二个页面已经出现

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    NSLog(@"页面viewDidAppear");
    
}

// 第二个页面将要消失了

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    NSLog(@"页面viewWillDisappear");
    
    
    
}

// 第二个页面已经消失

-(void)viewDidDisappear:(BOOL)animated{
    
    [super viewDidDisappear:animated];
    
    NSLog(@"页面viewDidDisappear");
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
